<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport"
			content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>采购入库-列表</title>
		<link rel="stylesheet" type="text/css" href="../../css/vant.css">
		<link rel="stylesheet" type="text/css" href="../../css/base.css" />
		<link rel="stylesheet" type="text/css" href="../../css/local.css" />
		<link rel="stylesheet" type="text/css" href="../../script/layer_new/css/layui.css" />
		<script type="text/javascript" src="../../script/jquery.js"></script>
		<script type="text/javascript" src="../../script/layer_new/layui.js"></script>
		<script type="text/javascript" src="../../script/vue.min.js"></script>
		<script type="text/javascript" src="../../script/vant.min.js"></script>
		<script type="text/javascript" src="../../script/fastclick.js"></script>
		<script type="text/javascript" src="../../script/base.js"></script>
		<style type="text/css">

		</style>
	</head>

	<body>
		<div id="app" v-cloak>
			<div class="box">
				<van-nav-bar class="head" :title="titleName" :safe-area-inset-top="true" left-arrow
					@click-left="onClickLeft">
					<div slot="right">
						<span @click="showSearch = true;">
							<van-icon name="search" size="18px"></van-icon>
						</span>
					</div>
				</van-nav-bar>

				<div class="content flex-box flex-direction-c">
					<van-list v-model="listLoading" :finished="listFinished" finished-text="没有更多了" @load="listOnLoad">
						<div class="content-refresh">
							<div class="module" v-for="(row,index) in dataList" @click="intoRow(row)">
								<div>
									<div class="label flex-box">
										<div class="sn">{{index+1}}</div>
										<div class="flex-main djcode">入库单号<span>{{row.FCode}}</span></div>
									</div>

									<div class="cmid flex-box">
										<van-divider></van-divider>
										<div>
											<div class="cmidIcon">
												<van-icon name="underway-o"></van-icon>
											</div>
											<div class="cmidLabel">入库日期</div>
											<div class="cmidValue">{{row.FDate}}</div>
										</div>
										<div>
											<div class="cmidIcon">
												<van-icon name="wap-home-o"></van-icon>
											</div>
											<div class="cmidLabel">入库仓库</div>
											<div class="cmidValue">{{row.FWarehouseName}}</div>
										</div>
										<div>
											<div class="cmidIcon">
												<van-icon name="manager-o"></van-icon>
											</div>
											<div class="cmidLabel">供应商</div>
											<div class="cmidValue">{{row.SupplyName}}</div>
										</div>

										<div class="approval" v-if="row.Approve">
											<img src="../../image/approval_success.png" />
										</div>
									</div>
								</div>
							</div>
						</div>
					</van-list>
				</div>

				<div class="fix-button" @click="addNew">
					<img src="../../image/addNew.png" />
				</div>
			</div>

			<van-popup v-model="showSearch" position="bottom">
				<div style="padding-bottom: 10px;">
					<van-cell title="入库时间" :value="searchData.FDate" @click="openDate(1)" is-link>
					</van-cell>
					<van-cell title="入库仓库" :value="searchData.FWarehouseName" @click="openBaseScreen('仓库')" is-link>
					</van-cell>
					<van-cell title="审核状态" :value="searchData.ApproveName" @click="openBaseScreen('审核状态')" is-link>
					</van-cell>
				</div>
				<div class="btn-padding" style="border-top: 1px solid #f0f0f0;">
					<van-row gutter="30">
						<van-col span="12">
							<van-button color="#51d0d0" size="small" block plain @click="reset">重置
							</van-button>
						</van-col>
						<van-col span="12">
							<van-button color="#51d0d0" size="small" block @click="searchList">查询
							</van-button>
						</van-col>
					</van-row>
				</div>
			</van-popup>

			<van-popup v-model="showDate" position="bottom">
				<van-datetime-picker v-model="currentDate" type="date" @confirm="confirmDate" @cancel="cancelDate"
					cancel-button-text="清空" />
			</van-popup>
		</div>
	</body>
	<script src="../../script/uni.webview.1.5.4.js"></script>
	<script type="text/javascript">
		// 开启 h5 页面 与 vue主页面的 信息交互
		document.addEventListener('UniAppJSBridgeReady', function() {

		})

		var dateIndex = 0;

		var vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				showSearch: false,
				titleName: '',
				type: '',
				listLoading: false,
				listFinished: true,
				pageSize: 20,
				pageIndex: 1,
				dataList: [],
				currentDate: new Date(),
				showDate: false,
				searchData: {
					FDate: '',
					PageSize: 20,
					pageIndex: 1,
					FWarehouseID: 0,
					FWarehouseName: '',
					ProductID: 0,
					ProductName: '',
					FWorkshopID: 0,
					FWorkshopName: '',
					Approve: -1,
					ApproveName: '',
				},
				baseScreenObj: {}, //弹窗选择列表参数
			},
			created() {

			},
			mounted() {

			},
			methods: {

				// 设置列表标题
				SetTitleName(menu) {
					let that = this;
					let data = JSON.parse(menu);
					that.titleName = data.APFunName + '列表';
				},

				// 请求列表数据
				SetServiceIP(IP) { // 从外部获取账套IP地址
					var that = this
					let data = JSON.parse(IP);
					APP.serverIP(data.serverIP);
					APP.IPAgreement(data.IPAgreement);
					$('.head').css({
						'padding-top': data.safeTop + 'px'
					})
					setTimeout(() => {
						that.getDataList();
					}, 300)
				},

				// 设置下拉返回
				SetChoiceData(content) {
					let selectItem = JSON.parse(content);

					if (selectItem.type == '仓库') {
						vm.searchData.FWarehouseID = selectItem.data.FWarehouseID;
						vm.searchData.FWarehouseName = selectItem.data.FWarehouseName;
					}
					if (selectItem.type == '审核状态') {
						vm.searchData.Approve = selectItem.data.Approve;
						vm.searchData.ApproveName = selectItem.data.ApproveName;
					}
				},

				reset() {
					vm.searchData.FDate = '';
					vm.searchData.PageSize = 20;
					vm.searchData.pageIndex = 1;
					vm.searchData.FWarehouseID = 0;
					vm.searchData.FWarehouseName = '';
					vm.searchData.Approve = -1;
					vm.searchData.ApproveName = '';
				},

				getDataList() {
					var that = this;
					that.showLoading = true;
					APP.jqueryAjax('GET_CGRKLB', that.searchData, function(res) {
						that.showLoading = false;
						that.listFinished = false;
						that.dataList = res.ds;
					})
				},

				listOnLoad() {
					var that = this;
					that.searchData.pageIndex++;
					APP.jqueryAjax('GET_CGRKLB', that.searchData, function(res) {
						that.listLoading = false;
						if (res.ds.length == 0) {
							that.listFinished = true;
						}
						that.dataList = that.dataList.concat(res.ds);
					})
				},

				searchList() {
					var that = this;
					that.showSearch = false;
					that.searchData.pageIndex = 1;

					this.getDataList();
				},

				openDate(index) {
					dateIndex = index;
					this.currentDate = new Date();
					this.showDate = true;
				},

				confirmDate(value) {
					if (dateIndex == 1) {
						this.searchData.FDate = APP.getFormatDate2('yyyy-MM-dd', value);
					}
					this.showDate = false;
				},

				cancelDate(value) {
					if (dateIndex == 1) {
						this.searchData.FDate = ''
					}
					this.showDate = false;
				},

				openBaseScreen(str) {
					let that = this;

					if (str == '仓库') {
						vm.baseScreenObj = {
							allowClear: false,
							cmd: 'Droplist_Warehouse',
							type: str,
							ListeningName: 'WmsListChoice',
							refresherEnabled: false,
							serverSearch: {
								isPaging: false, //是否分页
								showText: 'FWarehouseName', //查询结果显示的字段
								ChoiceDataKey: 'FWarehouseID',
								ChoiceDataData: vm.searchData.FWarehouseID
							},
							param: {

							}
						}
					}

					if (str == '审核状态') {
						vm.baseScreenObj = {
							allowClear: false,
							cmd: 'Droplist_Approve',
							type: str,
							ListeningName: 'WmsListChoice',
							refresherEnabled: false,
							serverSearch: {
								isPaging: false, //是否分页
								showText: 'ApproveName', //查询结果显示的字段
								ChoiceDataKey: 'Approve',
								ChoiceDataData: vm.searchData.Approve
							},
							param: {

							}
						}
					}

					this.sendMessage('baseScreen', vm.baseScreenObj);
				},

				addNew() {
					let obj = {
						FStockID: 0
					}
					this.sendMessage('add', obj);
				},

				intoRow(row) {
					let obj = {
						FStockID: row.FStockID
					}
					this.sendMessage('edit', obj);
				},

				sendMessage(action, data) {
					uni.postMessage({
						data: {
							action: action,
							data: data
						}
					})
				},

				onClickLeft() {
					uni.navigateBack();
				}
			}
		})
	</script>

</html>